<?php 

// get image detail 
if(isset($_GET['imgid']) && $_GET['imgid'] ){
    global $wpdb; 
    $current_img = $wpdb->get_row("SELECT * FROM ap_painting_img WHERE id = {$_GET['imgid']}");
    $imgs = explode("/", $current_img->url); 
    $img_name = $imgs[count($imgs) - 1];
    
    //update image 
    $upload = wp_upload_dir();
    if(isset($_POST['imgBase64'])){
            
            $img = str_replace('data:image/png;base64,', '', $_POST['imgBase64']);
            $img = str_replace(' ', '+', $img);
            $data = base64_decode($img);
            $file = $upload['path']."/".$img_name;
            $success = file_put_contents($file, $data);
            echo $upload['url']."/".$img_name;; 
            die; 
    }

}